//
//  WJNewfeatureController.m
//  weibo
//
//  Created by 王俊 on 15/12/29.
//  Copyright © 2015年 王俊. All rights reserved.
//

#import "WJNewfeatureController.h"
#import "WJTabBarController.h"


@interface WJNewfeatureController ()
@property(nonatomic,strong) UIPageControl  *pageControl;
@property(nonatomic,strong) UIImageView  *lastImage;
@end

@implementation WJNewfeatureController

- (void)viewDidLoad
{
    [super viewDidLoad];
    UIScrollView *scrollView = [[UIScrollView alloc]init];
    scrollView.frame = self.view.bounds;
    WJLog(@"%f",self.view.bounds.size.width);
    scrollView.contentSize = CGSizeMake(SCNWDTH * WJNewfeatureCount, SCNHEIGHT);
    for (int i = 0 ; i < WJNewfeatureCount; i++) {
        UIImageView *image = [[UIImageView alloc]init];
        image.image = [UIImage imageNamed:[NSString stringWithFormat:@"new_feature_%d",i + 1]];
        image.frame = CGRectMake(SCNWDTH * i , 0, SCNWDTH, SCNHEIGHT);
        [scrollView  addSubview:image];
        if (i == WJNewfeatureCount - 1) {
            _lastImage = image;
        }
 
    }
    scrollView.bounces = false;
    scrollView.pagingEnabled = true;
    scrollView.showsHorizontalScrollIndicator = false;
    scrollView.showsVerticalScrollIndicator = false;
    scrollView.delegate = self;
    
    [self.view addSubview:scrollView];
    
    UIPageControl *pageView = [[UIPageControl alloc]init];
    pageView.numberOfPages = WJNewfeatureCount;
    pageView.currentPageIndicatorTintColor = RGB(253, 98, 42);
    pageView.pageIndicatorTintColor = RGB(189, 189, 189);
    pageView.currentPage = 0;
    pageView.width = 100;
    pageView.height = 50;
    pageView.centerX = SCNWDTH/2;
    pageView.centerY = SCNHEIGHT - 80;
    _pageControl = pageView;
    _pageControl.userInteractionEnabled = false;
    
    [self.view addSubview:pageView];
    
    UIButton *shareBtn = [[UIButton alloc]init];
    shareBtn.size = pageView.size;
    shareBtn.centerX = pageView.centerX ;
    shareBtn.centerY = pageView.centerY - 140;
    shareBtn.width = 130;
    [shareBtn setTitle:@"我要分享" forState:UIControlStateNormal];
    [shareBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [shareBtn setImage:[UIImage imageNamed:@"new_feature_share_false"] forState:UIControlStateNormal];
    [shareBtn setImage:[UIImage imageNamed:@"new_feature_share_true"] forState:UIControlStateSelected];
    shareBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    shareBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
    //shareBtn.backgroundColor = [UIColor redColor];
    [shareBtn addTarget:self action:@selector(shareBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    _lastImage.userInteractionEnabled = true;
    [self.lastImage addSubview:shareBtn];
    
    UIButton *enterBtn = [[UIButton alloc]init];
    [enterBtn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button_highlighted"] forState:UIControlStateHighlighted];
    [enterBtn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button"] forState:UIControlStateNormal];
    [enterBtn setTitle:@"开始微博" forState:UIControlStateNormal];
    enterBtn.frame = shareBtn.frame;
    enterBtn.centerY = shareBtn.centerY + 60;
    enterBtn.height = 50;
    enterBtn.width = 120;
    [enterBtn addTarget:self action:@selector(enterBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.lastImage addSubview:enterBtn];
    
    shareBtn.centerX = pageView.centerX;
    enterBtn.centerX = pageView.centerX;
    


    
    

}

- (void)shareBtnClicked:(UIButton*)sender
{
    sender.selected = !(sender.isSelected);
    WJLog(@"%d",sender.selected);
    //WJLog(@"%@",sender.selected);
}

- (void)enterBtnClick:(UIButton*)sender
{
    WJLog(@"enterBtnClick");
    [UIApplication sharedApplication].keyWindow.rootViewController =  [[WJTabBarController alloc]init];
    
  
}


- (void)setUpViews
{
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    int page = (int)(scrollView.contentOffset.x + SCNWDTH/2)/ (int)SCNWDTH;
    //WJLog(@"%d",page);
    self.pageControl.currentPage = page;
}



@end
